package com.itheima.mapper;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    // 根据用户名和密码查询
    @Select("select * from tb_user where username = #{username} and password = #{password}")
    User select(@Param("username") String username, @Param("password") String password);

    // 根据用户名查询
    @Select("select * from tb_user where username = #{username}")
    User selectByUsername(String username);

    // 添加用户
    @Insert("insert into tb_user values(null,#{username},#{password},#{email},#{role})")
    void add(User user);

    // 注销用户
    @Delete("delete from tb_user where username = #{username}")
    void cancelUser(String username);

    // 根据用户id选择
    @Select("select * from tb_user where id = #{id}")
    User selectById(Integer id);

    // 根据id删除销售人员
    @Delete("delete from tb_user where id = #{id}")
    void deleteById(Integer id);

    // 添加销售人员
    @Insert("insert into tb_user values(null,#{username},#{password},#{email},#{role},#{adminId})")
    @ResultMap("userResultMap")
    void addStaff(User user);

    // 根据管理员id查找销售人员
    @Select("select * from tb_user where admin_id = #{adminId}")
    @ResultMap("userResultMap")
    List<User> selectByAdminId(Integer adminId);

    // 修改销售人员密码
    @Update("update tb_user set password = #{password} where id = #{id}")
    void updateStaffPasswordById(@Param("id") Integer id, @Param("password") String password);
}
